package com.aliyun.inventory.server.dao.mapper;

import com.aliyun.inventory.server.dao.entity.InventoryDO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

/**
 * ItemInventory Mapper （商品库存映射器）
 *
 * 
 * @date 2024/11/26
 */
@Mapper
public interface InventoryMapper extends BaseMapper<InventoryDO> {

    @Update("update tech_solution_inventory set remain_quantity = remain_quantity - #{deductionQuantity} where product_id = "
        + "#{productId} and remain_quantity >= #{deductionQuantity}")
    int deductInventory(@Param("productId") long productId, @Param("deductionQuantity") int deductionQuantity);
}
